package com.yjf.ljr.activity;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.yjf.ljr.R;
import com.yjf.ljr.dataclass.AboutUsDataClass;
import com.yjf.ljr.parser.RequestBuilder.RequestObject;
import com.yjf.ljr.util.AppUtil;

public class AboutUsActivity extends IjActivity {

	@ID("tvAboutUsTitle")
	private TextView mTvAboutUsTitle;
	@ID("tvAboutUs")
	private WebView mTvAboutUs;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about_us);

		initControls();
	}

	/** 初始化控件 **/
	private void initControls() {
		setLeftBtnClick();
		setTitleStr("关于我们");

		WebSettings settings = mTvAboutUs.getSettings();
		mTvAboutUs.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
		settings.setSupportZoom(false);
		settings.setBuiltInZoomControls(false);
		settings.setDomStorageEnabled(true);
		settings.setAppCacheMaxSize(1024 * 1024 * 9);// 设置缓冲大小
		String appCacheDir = this.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
		settings.setAppCachePath(appCacheDir);
		settings.setAllowFileAccess(true);
		settings.setAppCacheEnabled(true);
		settings.setCacheMode(WebSettings.LOAD_DEFAULT);
		mTvAboutUs.setVisibility(View.GONE);

		showProgressDialog();
		new AboutUsTask().execute();
	}

	class AboutUsTask extends AsyncTask<Void, Void, String> {
		private AboutUsDataClass dc = new AboutUsDataClass();

		@Override
		protected String doInBackground(Void... params) {
			RequestObject reqObj = new RequestObject();
			reqObj.method = "aboutUs";
			return requestDataAndGetErrorMsg(reqObj, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			if (!TextUtils.isEmpty(result)) {
				showToast(result);
			} else {
				if (!TextUtils.isEmpty(dc.aboutUs.title)) {
					mTvAboutUsTitle.setText(dc.aboutUs.title);
				} else {
					mTvAboutUsTitle.setVisibility(View.GONE);
				}

				if (!TextUtils.isEmpty(dc.aboutUs.content)) {
					mTvAboutUs.setVisibility(View.VISIBLE);
					mTvAboutUs.loadData(dc.aboutUs.content, "text/html; charset=UTF-8", null);
				}
			}
			dismissProgressDialog();
		}
	}

}
